/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package dao;

import java.util.List;
import javax.persistence.*;
import model.Materia;

/**
 *
 * @author ronaldomartins
 */
public class DaoMateria extends Dao{
    public List<Materia> buscarPorNome(String nome) {
        EntityManagerFactory emf = Persistence.createEntityManagerFactory("sarencaappPU");
        EntityManager em = emf.createEntityManager();
        List retorno = 
        em.createQuery(
           "SELECT m FROM Materia m WHERE m.nome LIKE :nome")
        .setParameter("nome", nome)
        .getResultList();
        
        return retorno;
    }   

    @Override
    public List listarTodos() {
        EntityManager em = getEntityManager();
        Query query = em.createQuery("SELECT m FROM Materia m");
        List objs = query.getResultList();
        return objs;          
    }

    @Override
    public Object buscarPorId(Long id) {
        Object obj = null;
        EntityManager em = getEntityManager();
        obj = em.find(Materia.class, id);
        return obj;
       
    }

    
    
   
}
